import { http } from "@/utils/http";
import { Result, arrayResult } from "../types";
import { exportExcel } from '@/utils/exportExcel'

export type racksData = {
  id?: number,
  code?: string,
  racksid?: number,
  layer?: number,
  column?: number,
  status?: number,
  attribute?: string,
  AuxiliaryName?: string,
  lochigh?: number,
  batch?: string,
  sort?: number,
  note?: string,
};

type racksSearch = {
  code?: string,
  status?: number,
  rackid?: number,
  category?: number,
  pageNumber: number,
  pageSize: number,
  sortName: string,
  sortType: number
}

// 货位列表
export const locationsList = (params?: racksSearch) => {
  return http.request<Result>("get", "/api/locations/List", { params });
};

// 新增货位
export const addLocations = (data?: racksData) => {
  return http.request<Result>("post", "/api/locations/Add", { data });
};

// 删除货位
export const getLocations = (id: number) => {
  return http.request<Result>("get", `/api/locations/Get/${id}`, {});
};

// 修改货位
export const updateLocations = (data?: racksData) => {
  return http.request<Result>("post", "/api/locations/UpdateModel", { data });
};

// 修改货位状态
export const UpdateStatus = (data: racksData) => {
  return http.request<Result>("post", `/api/locations/UpdateStatus/${data.id}`, { data: data.status });
};

// 类别select
export const getCategory = () => {
  return http.request<arrayResult>("get", "/api/Dict/ListByParentCode/Category", {});
};

// 指定货位出库
export const AppointOut = (data?: { [key: string]: any }) => {
  return http.request<Result>("post", "/api/job/AppointOut", { params: data });
};

// 手动删除货载
export const DelteLoad = (data?: { [key: string]: any }) => {
  return http.request<Result>("post", "/api/locations/DelteLoad", { params: data });
};

// 货位下拉
export const GetStorePlaceList = (data: any) => {
  return http.request<arrayResult>("get", "/api/locations/GetStorePlaceList", { params: data });
};

// 手动删除货载
export const Initialize = (data?: { [key: string]: any }) => {
  return http.request<Result>("post", "/api/locations/Initialize", { params: data });
};

// 所有货位下拉
export const GetAllStorePlaceList = (data?: any) => {
  return http.request<arrayResult>("get", "/api/locations/GetAllStorePlaceList", { params: data });
};

// 货位类型
export const Attribute = () => {
  return http.request<arrayResult>("get", `/api/Dict/ListByParentCode/Attribute`, {});
};

// 三向又左右距离
export const Ldristance = () => {
    return http.request<arrayResult>("get", `/api/Dict/ListByParentCode/LRDistance`, {});
  };
  

// 导出货位
export function excelLocations(data, fileName) {
  exportExcel('/api/locations/Excel', data, fileName);
}

// 删除货位
export const delLocations = (id: number) => {
  return http.request<Result>("post", `/api/locations/Delete/${id}`, {});
};

// 地图货位详情
export const GetLocCodeByStaId = (data?:any) => {
  return http.request<arrayResult>("get", `/api/locations/GetLocCodeByStaId`, { params:data });
};